public class CheckerBoard {
    private int[][] board = new int[3][3];//1代表X，-1代表O
    private Result statement = Result.DRAW;

    public void setBoard(int turn,String pos){
        int x = pos.charAt(1)-'1';
        int y = pos.charAt(0)-'A';
        board[x][y] = turn;
    }

    public Result getStatement (){
        return judge();
    }


    private Result judge(){
        for (int i = 0; i < 3; i++){
            if (board[i][0]+board[i][1]+board[i][2] == 3)
                return Result.X_WIN;
            if (board[i][0]+board[i][1]+board[i][2] == -3)
                return Result.O_WIN;
        }

        for (int i = 0; i < 3; i++){
            if (board[0][i]+board[1][i]+board[2][i] == 3)
                return Result.X_WIN;
            if (board[0][i]+board[1][i]+board[2][i] == -3)
                return Result.O_WIN;
        }

        int sum = board[0][0]+board[1][1]+board[2][2];
        if (sum == 3) return Result.X_WIN;
        else if (sum == -3) return Result.O_WIN;
        sum = board[0][2]+board[1][1]+board[2][0];

        if (sum == 3) return Result.X_WIN;
        else if (sum == -3) return Result.O_WIN;
        return Result.DRAW;
    }

    public void print(){
        String lineSeparator = System.getProperty("line.separator");
        StringBuilder ret = new StringBuilder("  A B C" + lineSeparator);
        for (int i = 0; i < 3; i++) {
            ret.append(i + 1);
            for (int j = 0; j < 3; j++) {
                if (board[i][j] == 1) ret.append(" X");
                else if (board[i][j] == -1) ret.append(" O");
                else ret.append(" _");
            }
            ret.append(lineSeparator);
        }
        System.out.print(ret);
    }
}
